﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using MediaData;

namespace MediaData
{
    public class MovieScanner : MediaItemScanner
    {
        public MovieScanner(string type) : base(type) { }

        public override void Scan(MediaRoot root, Predicate<MediaItem> exists, Action<MediaItem> mediaAdded)
        {
            string show;
            foreach (string showDir in Directory.GetDirectories(Path.Combine(root.Path, this.Type)))
            {
                show = Path.GetFileName(showDir);
                if (show.StartsWith(".") || show.StartsWith("_"))
                    continue;

                foreach (string file in Directory.GetFiles(showDir, "*", SearchOption.AllDirectories))
                {
                    MediaType mediaType =  GetType(Path.GetFileName(file));
                    if (mediaType != MediaType.Video && mediaType != MediaType.DiscImage)
                        continue;

                    MediaItem v = new MediaItem(root.Volume, file);
                    v.Title = show;
                    v.Type = Type;

                    if (!exists(v))
                    {
                        mediaAdded(v);
                    }
                }
            }
        }
    }
}
